<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
       
        .hour{
            width: 180px;
            height: 180px;
            background-color: black;
            color: blanchedalmond;    
            margin: auto;    
            position: relative;
            }
        .minute{
            width: 180px;
            height: 180px;
            background-color: black;
            color: blanchedalmond;
            margin: auto;
        }
        .second{
            width: 180px;
            height: 180px;
            background-color: black;
            color: blanchedalmond;
            margin: auto;
        }
    </style>
</head>
<body>
    <div>
        <span class="hour">1</span>
        <span class="minute">2</span>
        <span class="second">3</span>
    </div>
    <script>
        let hour = document.querySelector('.hour')
        let minute = document.querySelector('.minute')
        let second = document.querySelector('.second')
        let inputTime = +new Date('2021-1-22 8:12:00');
        countDown()
        setInterval(countDown,1000)//*每隔一秒就会自动刷新并且调用这个函数
        function countDown(){
            let nowTime = +new Date();
            let times = (inputTime - nowTime)/1000
            let h = parseInt(times / 60 % 60 %24);
            h = h < 10 ? '0' + h : h;
            hour.innerHTML = h;
            let m = parseInt(times / 60 % 60 );
            m = m < 10 ? '0' + m : m;
            minute.innerHTML = m;
            let s = parseInt(times / 60);
            s = s < 10 ? '0' + s : s;
            second.innerHTML = s;
        }

        //*停止定时器使用clearInterval（intervalId）
    </script>
</body>
</html>